﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ETADTools.Lib
{
  public class ObjectScriptBuilder : ScriptBuilder
  {
    public ObjectScriptBuilder(FormInfo info)
      : base(info)
    { }

    public override string SqlScript
    {
      get { return Resource.FORM_OBJECT; }
    }

    public override void Build()
    {
      // build script
      StringBuilder script = BuildBasicInfo();
      script.Replace(PlaceHolderForm.SqlObjectResource, Info.FieldList.ToSqlObjectResource());

      // get file name
      string scriptPath = Info.UpdaterPath + ETWebPath.Data + "0000 - ScriptObject.sql";

      // write the file
      using (StreamWriter writer = new StreamWriter(scriptPath))
      {
        writer.Write(script.ToString());
      }
    }
  }
}
